package com.gxsyh.nantie.order.provider.service.impl;
import java.util.Date;

import com.gxsyh.nantie.order.provider.TbSubsidyService;
import com.gxsyh.nantie.order.provider.domain.TbOrder;
import com.gxsyh.nantie.order.provider.domain.TbSubsidy;
import com.gxsyh.nantie.order.provider.mapper.TbSubsidyMapper;

import javax.annotation.Resource;
import com.gxsyh.nantie.order.provider.mapper.TbOrderMapper;
import com.gxsyh.nantie.order.provider.TbOrderService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

/**
 * @email yom535@outlook.com
 * @author: 刘锋嘉(Liu Fengjia)
 * @date: 2020/2/21
 * @time: 14:29
 * @Description: 
 */
@Transactional
@Service(version = "1.0.0")
public class TbOrderServiceImpl implements TbOrderService{

    @Resource
    private TbOrderMapper tbOrderMapper;


    @Override
    public int createOrder(TbOrder tbOrder) {
        return tbOrderMapper.insert(tbOrder);
    }

    @Override
    public int updateOrderIsPlan(Long orderId) {
        Example example=new Example(TbOrder.class);
        example.createCriteria().andEqualTo("id",orderId);
        TbOrder tbOrder=new TbOrder();
        tbOrder.setOrderStatus(2);
        return tbOrderMapper.updateByExampleSelective(tbOrder,example);
    }

    @Override
    public int updateOrderIsDone(Long orderId) {
        Example example = new Example(TbOrder.class);
        example.createCriteria().andEqualTo("id", orderId);
        TbOrder tbOrder = new TbOrder();
        tbOrder.setOrderStatus(3);
        return tbOrderMapper.updateByExampleSelective(tbOrder, example);
    }

    @Override
    public int uodateOrderIsPay(Long orderId,int payInfo,Long payDepartmentId) {
        Example example = new Example(TbOrder.class);
        example.createCriteria().andEqualTo("id", orderId);
        TbOrder tbOrder = new TbOrder();
        tbOrder.setPayStatus(1);

        if (payInfo==0){
            tbOrder.setPayMethod("WechatPay");
        }
        else if (payInfo==1)
        {
            tbOrder.setPayMethod("AliPay");
        }
        tbOrder.setPayDepartmentId(payDepartmentId);
        return tbOrderMapper.updateByExampleSelective(tbOrder, example);
    }
}
